<template>
  <div>
    <div class="user-opt">
      <div>
        <h1>我的菜单</h1>
      </div>
      <el-button v-if="isMe" @click="creatingCaidan = true">创建菜单</el-button>
    </div>

    <div class="list-box">
      <div class="empty-status-box" v-if="list.length == 0">
        <span v-if="isMe">
          你还没有任何菜单哦~，快去<span class="link-btn">创建</span>一个吧！
        </span>
        <span v-else> 该用户没有任何公开的菜单，快去别处看看吧~ </span>
      </div>
      <div
        class="list-node"
        v-for="(item, i) in list"
        :key="i"
        @click="$router.push('/caidan/1')"
      >
        <caidan-type-list :id="item"></caidan-type-list>
        <el-dropdown class="opts" v-if="isMe">
          <!-- <span class="link-btn" style="padding: 0 1.25rem">
              {{ userInfo.username }}
              <i class="el-icon-arrow-down el-icon--right"></i>
            </span> -->
          <a-icon type="more" />
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="setStatusOpt(i)">{{
              getStatusOptStr(item)
            }}</el-dropdown-item>
            <el-dropdown-item @click.native="del(i)">删除</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>

    <el-dialog title="创建菜单" :visible.sync="creatingCaidan" width="30%">
      <el-form>
        <el-form-item label="菜单名称">
          <el-input v-model="createForm.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="菜单描述">
          <el-input
            v-model="createForm.text"
            autocomplete="off"
            type="textarea"
            :rows="5"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="creatingCaidan = false">取 消</el-button>
        <el-button type="primary" @click="createCaidan()"
          >确 定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import CaidanTypeList from "../CaidanShowType/CaidanTypeList.vue";

export default {
  props: {
    isMe: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      list: [1, 2, 3, 4, 5],
      creatingCaidan: false,
      createForm: {
        name: "",
        text: "",
      },
    };
  },
  methods: {
    getStatusOptStr(id) {
      if (id == 1) return "设置为仅自己可见";
      return "设置为全部用户可见";
    },
    setStatusOpt(i) {
      //todo 取反
      this.$msg.success("设置成功");
    },
    del(i) {
      this.list.splice(i, 1);
      this.$msg.success("删除成功");
    },
    createCaidan(){
      this.$router.push('/caidan/1');
      this.$msg.success("创建成功");
      
    }
  },

  components: { CaidanTypeList },
};
</script>

<style lang="less" scoped>
.user-opt {
  display: flex;
  justify-content: space-between;
}
.list-box {
  width: 100%;
  .list-node {
    margin: 10px 0;
    position: relative;
    .opts {
      position: absolute;
      top: 10px;
      right: 10px;
      font-size: 25px;
    }
  }
}
.empty-status-box {
  height: 200px;
  line-height: 200px;
  text-align: center;
}
.el-dialog{
  width: 30%;
}
</style>

